from basic_info.models import WarehouseModel
from rest_framework import serializers


class WarehouseSerializer(serializers.ModelSerializer):
    """
    仓库信息的序列化器
    """

    class Meta:
        model = WarehouseModel
        fields = '__all__'


# 用于查询结果的序列化器，因为需要显示负责人的真实名字
class WarehouseSearchSerializer(serializers.ModelSerializer):
    """
    查询结果的序列化, SlugRelatedField,返回主表的某一个字段值:slug_field可以指定一个需要展示的字段
    """
    leader_user = serializers.SlugRelatedField(slug_field='real_name', read_only=True)

    class Meta:
        model = WarehouseModel
        fields = '__all__'
